package com.axzh.interview.collection;

public class QueueStructure {

	public static void main(String[] args) {

	}

}

class Queue_1<E> {
	
	private int top;
	private int maxSize;
	
	private Object[] elementData;
	
	public Queue_1() {
		top=-1;
		maxSize=100;
		elementData = new Object[maxSize];
	}
	
	public Queue_1(int maxSize) {
		top=-1;
		this.maxSize=maxSize;
		elementData = new Object[maxSize];
	}
	
	public void push(E e) {
		if(top==maxSize) {
			System.out.println("栈为空！");
		} else {
			elementData[++top]=e;
		}
	}
	
	@SuppressWarnings("unchecked")
	public E peek() {
		if(isEmpty()) {
			System.out.println("栈为空！");
			return null;
		} else {
			return (E) elementData[top];
		}
	}
	
	@SuppressWarnings("unchecked")
	public E pop() {
		if(isEmpty()) {
			System.out.println("栈为空！");
			return null;
		} else {
			return (E) elementData[top--];
		}
	}
	
	public boolean isEmpty() {
		return top==-1;
	}
}